package com.watereast;

import com.sun.istack.internal.NotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

public class RedisTest {
    @NotNull
    public static List<Object> readEXL(String filePath) throws IOException {
        Map<Object, Object> map = new HashMap<>();
        List<Object> list = new ArrayList();
        FileInputStream inputStream = null;
        XSSFWorkbook workbook = null;
        try {
            inputStream = new FileInputStream(new File(filePath));
            workbook = new XSSFWorkbook(inputStream);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        XSSFSheet xSSFSheet = workbook.getSheetAt(0);
        int i = 0;
        for (Row row : xSSFSheet) {
            for (Cell cell : row) {
                if (cell != null) {
                    i++;
                    map.put(Integer.valueOf(i), cell);
                    list.add(map.get(Integer.valueOf(i)));
                }
            }
        }
        workbook.close();
        inputStream.close();
        return list;
    }

    public static void main(String[] args) throws IOException {
        String filePathKey = "C:\\Users\\nietao-002\\Desktop\\uuid.xlsx";
        String filePathValue = "C:\\Users\\nietao-002\\Desktop\\userInfo.xlsx";
        Jedis jedis = new Jedis("10.186.67.14", 31002);
        jedis.auth("Zdnsx@2017");
        System.out.println("+ jedis.ping());
                Pipeline pipelined = jedis.pipelined();
        List<Object> objectKeys = readEXL(filePathKey);
        List<Object> objectValues = readEXL(filePathValue);
        int keylists = objectKeys.size();
        int listLength = objectValues.size();
        String key = null;
        String value = null;
        for (int i = 0; i < keylists; i++) {
            key = objectKeys.get(i).toString();
            value = objectValues.get(i).toString();
            pipelined.set(key, value);
            if (i % 1000 == 0)
                pipelined.sync();
        }
        Set<String> keys = jedis.keys("insuranceBind:userInfo:ox6grejwionuserInfonew*");
        String s = jedis.get("insuranceBind:userInfo:ox6grejwionuserInfonew1");
        System.out.println("key+ keys.size());
                System.out.println("value---" + s);
        try {
            pipelined.close();
            jedis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
